/**
 * 管理系统-登录-接口路由模块
 */
  const express = require('express')
  const router = express.Router()
 
 /**
  * 引入其他模块
  */
  const db = require('../../utils/db')
  const md5 = require('blueimp-md5')
 
  router.get('/api/login', (req, res, next) => {
    const {admin_email, admin_pwd} = req.query
    const sql = 'select * from ali_admin where admin_email = ? and admin_pwd = ?'
    db.query(sql, [admin_email, md5(admin_pwd)], (err, result) => {
      if (err) return next(err)
      if (result.length == 1) {
        req.session.user = result[0]
        res.status(200).json({
          success: true,
          msg: '登录成功',
          data: {}
        })
      } else {
        res.status(200).json({
          success: false,
          msg: '邮箱或密码错误'
        })
      }
    })
  })

  router.get('/api/logout', (req, res, next) => {
    delete req.session.user
    res.redirect('/admin/login')
  })
 
  module.exports = router